#ifndef __B_HAL_LCD_H
#define __B_HAL_LCD_H

#include "b_config.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * \addtogroup B_HAL
 * \{
 */

/**
 * \addtogroup LCD
 * \{
 */

/**
 * \defgroup LCD_Exported_Types
 * \{
 */

typedef enum {
    LCD_SEG_0 = 0,
    LCD_SEG_1,
    LCD_SEG_2,
    LCD_SEG_3,
    LCD_SEG_4,
    LCD_SEG_5,
    LCD_SEG_6,
    LCD_SEG_7,
    LCD_SEG_8,
    LCD_SEG_9,
    LCD_SEG_10,
    LCD_SEG_11,
    LCD_SEG_12,
    LCD_SEG_13,
    LCD_SEG_14,
    LCD_SEG_15,
    LCD_SEG_16,
    LCD_SEG_17,
    LCD_SEG_18,
    LCD_SEG_19,
    LCD_SEG_20,
    LCD_SEG_21,
    LCD_SEG_22,
    LCD_SEG_23,
    LCD_SEG_24,
    LCD_SEG_25,
    LCD_SEG_26,
    LCD_SEG_27,
    LCD_SEG_28,
    LCD_SEG_29,
    LCD_SEG_30,
    LCD_SEG_31,
    LCD_SEG_32,
    LCD_SEG_MAX
} bLcdSeg_t;
typedef enum {
    LCD_COM_0 = 0,
    LCD_COM_1,
    LCD_COM_2,
    LCD_COM_3,
    LCD_COM_MAX
} bLcdCom_t;
typedef struct {
    uint8_t contrast;    /* LCD contrast level (0-100) */
    uint8_t duty;        /* LCD duty cycle (1/2, 1/3, 1/4, etc.) */
    uint8_t bias;        /* LCD bias (1/2, 1/3, etc.) */
    uint32_t frequency;  /* LCD frame frequency in Hz */
} bLcdConfig_t;

/**
 * \}
 */

/**
 * \defgroup LCD_Exported_Functions
 * \{
 */

/**
 * \brief Initialize LCD peripheral
 * \param config Pointer to LCD configuration structure
 * \return 0: success, -1: error
 */
int bHalLcdInit(bLcdConfig_t *config);

/**
 * \brief Deinitialize LCD peripheral
 * \return 0: success, -1: error
 */
int bHalLcdDeInit(void);

/**
 * \brief Turn on LCD display
 * \return 0: success, -1: error
 */
int bHalLcdOn(void);

/**
 * \brief Turn off LCD display
 * \return 0: success, -1: error
 */
int bHalLcdOff(void);

/**
 * \brief Set LCD contrast level
 * \param contrast Contrast level (0-100)
 * \return 0: success, -1: error
 */
int bHalLcdSetContrast(uint8_t contrast);

/**
 * \brief Clear all segments
 * \return 0: success, -1: error
 */
int bHalLcdClear(void);

/**
 * \brief Set segment state
 * \param seg Segment to set
 * \param state 1: on, 0: off
 * \return 0: success, -1: error
 */
int bHalLcdSetSeg(bLcdSeg_t seg, bLcdCom_t com, uint8_t state);

/**
 * \brief Display a number on specified digit position
 * \param digit Digit position (0-based)
 * \param number Number to display (0-9)
 * \return 0: success, -1: error
 */
int bHalLcdDisplayNumber(uint8_t digit, uint8_t number);

/**
 * \brief Display a string on LCD
 * \param str String to display
 * \param start_pos Starting position
 * \return 0: success, -1: error
 */
int bHalLcdDisplayString(const char *str, uint8_t start_pos);

/**
 * \brief MCU-specific LCD initialization
 * \param config Pointer to LCD configuration structure
 * \return 0: success, -1: error
 */
int bMcuLcdInit(bLcdConfig_t *config);

/**
 * \brief MCU-specific LCD deinitialization
 * \return 0: success, -1: error
 */
int bMcuLcdDeInit(void);

/**
 * \brief MCU-specific LCD turn on
 * \return 0: success, -1: error
 */
int bMcuLcdOn(void);

/**
 * \brief MCU-specific LCD turn off
 * \return 0: success, -1: error
 */
int bMcuLcdOff(void);

/**
 * \brief MCU-specific LCD contrast setting
 * \param contrast Contrast level (0-100)
 * \return 0: success, -1: error
 */
int bMcuLcdSetContrast(uint8_t contrast);

/**
 * \brief MCU-specific LCD clear
 * \return 0: success, -1: error
 */
int bMcuLcdClear(void);

/**
 * \brief MCU-specific segment setting
 * \param seg Segment to set
 * \param state 1: on, 0: off
 * \return 0: success, -1: error
 */
int bMcuLcdSetSeg(bLcdSeg_t seg, bLcdCom_t com, uint8_t state);


/**
 * \brief Set all segments
 * \param state 1: on, 0: off
 * \return 0: success, -1: error
 */
int bHalLcdSetAllSeg(uint8_t state);
uint8_t bHalLcdReadSegState(bLcdSeg_t seg, bLcdCom_t com);
uint8_t bMcuLcdReadSegState(bLcdSeg_t seg, bLcdCom_t com);
/**
 * \}
 */

/**
 * \}
 */

/**
 * \}
 */

#ifdef __cplusplus
}
#endif

#endif /* __B_HAL_LCD_H */ 